<script type="text/javascript">
$(document).ready(function() {
	bindTextraw();
	$(".s_active_page").hide();
	bindAjaxForm($("#stuactivesubmit"),s_a_ajax_onSuccess,s_a_ajax_onError);
	checkImageUpdaterScript();
	reloadListener();

});
function onImageUpdaterScriptLoad(){
	s_i_load("s_activity_file_updater");
	
}
function s_a_ajax_onError(data) {
	showMessage("s_a_result",-101, err);
}
function s_a_ajax_onSuccess(data) {
    try {
        if(data["code"]==0){
        	mainPageLoad("index.php?mod=home&childmod=home&ajax=true&op=activity&aid="+data.data.aid);
        }
    	showMessage("s_a_result",data["code"], data["message"]);
    } catch(ex) {
    	showMessage("s_a_result",-31, err);
    }
}
function unloadImageUpdater(){
	$("#s_activity_image_updater").html("").hide();
	s_i_reset();
}
function loadImageUpdater() {
	$("#s_activity_image_updater").show();
	$("#s_activity_image_updater").load("index.php?mod=home&childmod=home&ajax=true&op=image_updater_insert");
}
function reloadImageUpdater() {
	$("#s_activity_image_updater").load("index.php?mod=home&childmod=home&ajax=true&op=image_updater_insert");
}
function image_update_callback(state,data) {
	if(state){
		if(data.code==0){
			addActivityImage(data);
			reloadImageUpdater();
			return;
		}
		showMessage("s_i_u_result",data["code"], data["message"]);
	}else{
		showMessage("s_i_u_result",-101,"上传失败，服务器传来未知数据，请前往Console查看");
		console.log(data);
	}
	
}
function image_cancel_callback() {
	unloadImageUpdater();
}
function addActivityImage(data) {
	webPath = data.data.webPath;
	rid = data.data.rid;
	$(".s_append_images").prepend($("<img class='s_append_image' width='100px' height='100px' src='/images/wireframe/image.png' rid=''>")
			.attr("rid", rid)
			.attr("src", webPath)
			.addClass("" + rid)
			.dblclick(function(){console.log($(this).attr("rid"));removeActivityImage($(this).attr("rid"));}));
	$("#stuactivesubmit").prepend($("<input class='s_append_image_checkbox' type='checkbox' name='images[]' style='display:none;' checked>").attr("value",rid).addClass("" + rid))
}
function removeActivityImage(rid){
	console.log($(".s_append_images."+rid));
	$(".s_append_image."+rid).remove();
	$(".s_append_image_checkbox."+rid).remove();
}
function bar_action(f, e) {
	$(".s_activity_bar").removeClass("active");
	e.addClass("active");
	reload_bar(f);
}
function reload_bar(f){
	if (f == 0) {
		loadImageUpdater();
		$("#s_activity_image").show();
		$("#s_activity_file").hide();
	} else {
		loadFileUpdater();
		$("#s_activity_file").show();
		$("#s_activity_image").hide();
	}
}
$('#stuactivesubmit').form({
    fields: {
    	subject: {
            identifier: 'subject',
            rules: [{
                type: 'empty',
                prompt: '请输入标题'
            }]
        },
        content: {
            identifier: 'content',
            rules: [{
                type: 'empty',
                prompt: '请输入内容'
            }]
        }
}});
</script>
<h3>发表动态</h3>
<div class="ui message">分享生活的点点滴滴</div>
<form class="ui form" id="stuactivesubmit" url="index.php?mod=home&childmod=home&ajax=true&op=publishactivity">
	<div class="ui success message hidden" id="s_a_result"></div>
	<input type="hidden" name="actiontype" value="active">
	<div class="field">
		<input type="text" name="subject" placeholder="标题">
	</div>
	<div class="field">
		<textarea class="s_activity_content" rows="10" name="content"></textarea>
	</div>
	<div class="inline fields">
		<label for="fruit">请选择可视等级</label>
		<div class="field">
			<div class="ui radio checkbox">
				<input type="radio" name="view_level" checked="" value="0" tabindex="0" class="hidden">
				<label>公开</label>
			</div>
		</div>
		<div class="field">
			<div class="ui radio checkbox">
				<input type="radio" name="view_level" tabindex="0" value="1" class="hidden">
				<label>仅自己可见</label>
			</div>
		</div>
	</div>
	<div class="ui compact menu">
		<a class="item s_activity_bar" onClick="bar_action(0,$(this));">上传图片</a>
		<a class="item s_activity_bar" onClick="bar_action(1,$(this));">上传文件</a>
	</div>
	<div class="ui attached segment s_active_page image" id="s_activity_image">
		<div class="s_append_images ui images">
			<input type='checkbox' name='images[]' style='display: none;'>
		</div>
		<div class="" id="s_activity_image_updater"></div>
	</div>
	<div class="ui attached segment s_active_page file" id="s_activity_file">
		<div class="s_append_files ui images"></div>
		<div class="" id="s_activity_file_updater"></div>
	</div>
	<br />
	<br />
	<div class="ui error message"></div>
	<button class="ui fluid submit button" type="submit">发表</button>
</form>
